<html>
<head><meta charset="utf-8"><title>IntellijRules in completions · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html">IntellijRules in completions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="229940179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/229940179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#229940179">(Mar 11 2021 at 22:30)</a>:</h4>
<p>I'm checking the way we complete the modules in <code>mod_.rs</code> and for test like</p>
<div class="codehilite"><pre><span></span><code>#[test]
    fn module_partially_named() {
        check(
            r#&quot;
            //- /lib.rs
            mod a$0
            //- /foo.rs
            fn foo() {}
            //- /bar/mod.rs
            fn bar() {}
            //- /bar/ignored_bar.rs
            fn ignored_bar() {}
        &quot;#,
            expect![[r#&quot;
                md bar;
            &quot;#]],
        );
    }
</code></pre></div>
<p>we actually have no completions.</p>
<p>The completion considers <code>a</code> to be the current module (returning it in the <code>let current_module = ctx.scope.module()?;</code>) and I want to determine this fact to throw this incomplete module away from the path lookups.</p>
<p>Besides the current module, I have the <code>mod_under_caret: ast::Module</code> so checking that their names match sounds reasonable, but the name of that ast module is actually <code>aintellijRulezz</code>.<br>
What's even more odd,  when I call <code>ctx.scope.module()?.definition_source(ctx.db).value</code> and extract the module ast to print, it's different to the one that the ast the completion gets.</p>
<p>What would be a good way to understand that I'm on some odd unfinished module-like thing in this test?</p>



<a name="229993136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/229993136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#229993136">(Mar 12 2021 at 08:33)</a>:</h4>
<p>IIRC <code>intelliJRulezz</code> is an identifier we insert at the completion point (after <code>.</code>) to make things parse correctly</p>



<a name="230001867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230001867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230001867">(Mar 12 2021 at 09:51)</a>:</h4>
<p>^</p>



<a name="230002142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230002142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230002142">(Mar 12 2021 at 09:53)</a>:</h4>
<blockquote>
<p>What's even more odd, when I call ctx.scope.module()?.definition_source(ctx.db).value and extract the module ast to print, it's different to the one that the ast the completion gets.</p>
</blockquote>
<p>The completion context actually has two trees, one with the synthetic inserted Identifier and one without</p>



<a name="230002154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230002154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230002154">(Mar 12 2021 at 09:54)</a>:</h4>
<p>from what I remember</p>



<a name="230003832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230003832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230003832">(Mar 12 2021 at 10:06)</a>:</h4>
<p>yeah, that's because we can parse the code with the insert identifier, but we can't really analyze it any further, so we have to use the original trees for that</p>



<a name="230003942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230003942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230003942">(Mar 12 2021 at 10:07)</a>:</h4>
<p>I think the inserted identifier is a red herring here though, the problem is that <code>mod a&lt;|&gt;</code> gets parsed as <code>mod a {&lt;|&gt;}</code> I guess</p>



<a name="230004203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230004203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230004203">(Mar 12 2021 at 10:10)</a>:</h4>
<p>I mean, the problem is that we consider <code>a</code> the current module in this situation</p>



<a name="230009992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230009992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230009992">(Mar 12 2021 at 10:58)</a>:</h4>
<p>Yes, all that's very fishy indeed.</p>
<p>I have no idea where to adjust the code related to the module resolution, but feels like manually cutting out that synthetic marker is the worst, so I'm a bit clueless right now, asking for code pointers and/or the path to tackle that.</p>
<p>As usual, a small anticipated fix turned into a long expedition <span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span></p>



<a name="230011521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules%20in%20completions/near/230011521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/IntellijRules.20in.20completions.html#230011521">(Mar 12 2021 at 11:10)</a>:</h4>
<p>I would hope that if we have <code>mod a&lt;|&gt; {}</code>, we don't consider it as being inside the module (otherwise that's a straight-up bug). If not, maybe we need some special tweaking for the <code>mod a&lt;|&gt;</code> case.  I think the relevant code is <code>analyze_impl</code> / <code>find_container</code> in <code>semantics.rs</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>